/** 雷鸟之翼,从婆娑罗改装来,增加一个必定蓄力完成的快捷键,不会被连发影响

  By setycyas @2025-10-07
*/

/* 全局设定
*/ {
#Warn
#MaxThreadsPerHotkey 1
SetWorkingDir(A_ScriptDir)
#Include "..\Class\FaceDetector.2.ahk"
#Include "..\Class\CommonMacro.2.ahk"
#Include "..\Class\CommonUI.2.ahk"
#Include "..\Class\MyFuns.2.ahk"
#Include "..\Class\MyEmu.2.ahk"
#Include "..\Class\OrderMap.2.ahk"
;SendMode("Event")
SendMode("Input")
}

/* 制作雷鸟之翼的宏类
*/ 
class GigawingMacro extends CommonMacro {

  pressDuration := 30
  aFlag := False ;a键按下与否的标记

  /* 函数
  */
  ;按下A与放开A
  _按下A(){
    if (this.aFlag) {
      this._up(1)
      this.aFlag := False
      sleep(30)
      this._down(1)
      this.aFlag := True
    } else {
      this._down(1)
      this.aFlag := True
    }
  }
  _放开A(){
    if (this.aFlag) {
      this._up(1)
      this.aFlag := False
    }
  }
  ;一键从蓄力到放开
  _一键蓄力(duration){
    this._按下A()
    sleep(duration)
    this._up(1)
    this.aFlag := False
  }
  
  /* 新增的宏函数
  */
  ;优先度最高覆盖连发的蓄力
  _必定蓄力(key){
    this._一键蓄力(this.testParams[1]) ;1000
  }
  
  ;改装一下连发A,当被蓄力斩中断后判断一下按键的放开状态
  _连发A(key){
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    while (MyFuns.getVkState(vk)) {
      this._按下A()
      sleep(this.pressDuration)
      this._放开A()
      sleep(this.autoFireDelay)
    }
  }
  ;在按下攻击键蓄力时强制终止连射然后开始蓄力
  _手动蓄力(key){
    local vk := GetKeyVK(MyFuns.getHotkey(key))
    if (this.aFlag) {
      this._up(1)
      this.aFlag := False
    }
    this._down(1)
    while (MyFuns.getVkState(vk)) {
      sleep(20)
    }
    this._up(1)
  }
  ;直接按下蓄力
  _蓄力A(key){
    if (this.aFlag) {
      this._up(1)
      this.aFlag := False
    }
    sleep(20)
    this._down(1)
    this.aFlag := True
  }

  /* 重载宏接口
  */
  _setMacro(){
    static obm := ObjBindMethod ;函数名简写,制作对象绑定函数
    ;制作宏相关Map
    this.macroMap := OrderMap()
    this.macroMap["连发A"] := obm(this, "_连发A")
    this.macroMap["必定蓄力"] := obm(this, "_必定蓄力")
    this.macroMap["手动蓄力"] := obm(this, "_手动蓄力")
    this.macroMap["蓄力A"] := obm(this, "_蓄力A")
    ;制作指定宏顺序的数组
    this.macroArr := this.macroMap.getKeys()
  }
}

/* 制作雷鸟之翼专用UI
*/
class GigaWingUI extends CommonUI {

  DEFAULT_HOTKEYS := "~s,~d,~a,x"
  EXE_ARRAY := ["mame.exe", MyEmu.XZONE, MyEmu.FBNEO64, MyEmu.FBASX64]

  /* 构造函数
  */
  __New(macro){
    super.__New("GigaWing", macro)
    this._preset := OrderMap([
      "默认", ["连发A", "必定蓄力", "手动蓄力", "蓄力A"],
    ])
    this.MACRO_PRIORITY["连发A"] := "p-1"
    this.MACRO_PRIORITY["必定蓄力"] := "p10"
    this._macro.UI := this ;绑定UI
  }

  /* 重写接口
  */

  /* 重写setup,更改可选的exe,读入预设
  */
  setup(){
    super.setup()
    this._myGui.opt("+AlwaysOnTop")
    this._myGui.show("x1100 y330")
    this.readPresetMenu("默认")
  }

}

/* 运行当前脚本
*/ 
if (A_ScriptName == "雷鸟之翼.2.ahk") {
  face := FaceDetector() ;方向检测对象
  macro := GigawingMacro(face, ["q","space"]) ;宏对象,有界面时第二个参数可以随便写但长度不要小于2
  ;新建界面对象并显示
  ui := GigawingUI(macro)
  ui.setup()
  ;更新组件内容
  ;ui._exeComboBox.Choose(MyEmu.XZONE)
  ui._exeComboBox.Choose(MyEmu.MAME)
  ui._gameKeyEdit.Text := "q,space"
  ui._hotkeyEdit.Text := "~s,~d,~a,x"
  ui._fpsEdit.Text := 10
  ui._testEdit.Text := "1500,30,30,30"
  ui.readPresetMenu("默认")
}
